var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
	res.render('redirect.html', { title: 'WeShare'});

});

router.get('/:city', function(req, res, next) {
	var u = req.headers['user-agent'];
	// 页面参数
	var paramas = {
		// 页面标题
		title: 'WeShare - ' + req.params.city,
		// 切换城市信息
		changeCtiyMassage: ''
	}
	if (req.query.code) {
		paramas.changeCtiyMassage = 'Switched to a nearby city with Free WiFi'
	}
	// 根据不同终端跳转不同页面
	if (u.indexOf('iPhone') == -1 && u.indexOf('iPad') == -1 && u.indexOf('iTouch') == -1 && u.indexOf('Android') == -1) {
	  	res.render('index.html', paramas);
	} else {
  		res.render('phone.html', paramas);
	}
});

module.exports = router;
